/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:28
*/
KISSY.add("html-parser/dtd",[],function(a){var a=a.merge,b={isindex:1,fieldset:1},c={input:1,button:1,select:1,textarea:1,label:1},f=a({a:1},c),d=a({iframe:1},f),h={hr:1,ul:1,menu:1,div:1,blockquote:1,noscript:1,table:1,center:1,address:1,dir:1,pre:1,h5:1,dl:1,h4:1,noframes:1,h6:1,ol:1,h1:1,h3:1,h2:1},g={ins:1,del:1,script:1,style:1},l=a({b:1,acronym:1,bdo:1,"var":1,"#text":1,abbr:1,code:1,br:1,i:1,cite:1,kbd:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,dfn:1,span:1},g),m=a({sub:1,img:1,object:1,
sup:1,basefont:1,map:1,applet:1,font:1,big:1,small:1},l),j=a({p:1},m),c=a({iframe:1},m,c),m={img:1,noscript:1,br:1,kbd:1,center:1,button:1,basefont:1,h5:1,h4:1,samp:1,h6:1,ol:1,h1:1,h3:1,h2:1,form:1,font:1,"#text":1,select:1,menu:1,ins:1,abbr:1,label:1,code:1,table:1,script:1,cite:1,input:1,iframe:1,strong:1,textarea:1,noframes:1,big:1,small:1,span:1,hr:1,sub:1,bdo:1,"var":1,div:1,object:1,sup:1,strike:1,dir:1,map:1,dl:1,applet:1,del:1,isindex:1,fieldset:1,ul:1,b:1,acronym:1,a:1,blockquote:1,i:1,
u:1,s:1,tt:1,address:1,q:1,pre:1,p:1,em:1,dfn:1},k=a({a:1},c),n={tr:1},o={"#text":1},p=a({param:1},m),e=a({form:1},b,d,h,j),i={li:1},t={base:1,link:1,meta:1,title:1},r=a(t,{style:1,script:1}),q={head:1,body:1},u={address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1},a={$nonBodyContent:a({html:1},q,t),$block:u,$blockLimit:{body:1,div:1,td:1,th:1,caption:1,form:1},$inline:k,$body:a({script:1,style:1},
u),$cdata:{script:1,style:1},$empty:{area:1,base:1,br:1,col:1,hr:1,img:1,input:1,link:1,meta:1,param:1},$listItem:{dd:1,dt:1,li:1},$list:{ul:1,ol:1,dl:1},$nonEditable:{applet:1,button:1,embed:1,iframe:1,map:1,object:1,option:1,script:1,textarea:1,param:1},$removeEmpty:{abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,"var":1},$tabIndex:{a:1,area:1,button:1,input:1,object:1,
select:1,textarea:1},$tableContent:{caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1},html:q,head:r,style:o,body:e,base:{},link:{},meta:{},title:o,col:{},tr:{td:1,th:1},img:{},colgroup:{col:1},noscript:e,td:e,br:{},th:e,center:e,kbd:k,button:a(j,h),basefont:{},h5:k,h4:k,samp:k,h6:k,ol:i,h1:k,h3:k,option:o,h2:k,form:a(b,d,h,j),select:{optgroup:1,option:1},font:k,ins:k,menu:i,abbr:k,label:k,table:{thead:1,col:1,tbody:1,tr:1,colgroup:1,caption:1,tfoot:1},code:k,script:o,tfoot:n,cite:k,
li:e,input:{},iframe:e,strong:k,textarea:o,noframes:e,big:k,small:k,span:k,hr:{},dt:k,sub:k,optgroup:{option:1},param:{},bdo:k,"var":k,div:e,object:p,sup:k,dd:e,strike:k,area:{},dir:i,map:a({area:1,form:1,p:1},b,g,h),applet:p,dl:{dt:1,dd:1},del:k,isindex:{},fieldset:a({legend:1},m),thead:n,ul:i,acronym:k,b:k,a:c,blockquote:e,caption:k,i:k,u:k,tbody:n,s:k,address:a(d,j),tt:k,legend:k,q:k,pre:a(l,f),p:k,em:k,dfn:k},f="article,figure,nav,aside,section,footer".split(","),s;for(s in a)for(var v in a[s])if("div"===
v)for(b=0;b<f.length;b++)a[s][f[b]]=a[s][v];for(b=0;b<f.length;b++)a[f[b]]=a.div;a.$empty["!doctype"]=1;return a});KISSY.add("html-parser/lexer/cursor",[],function(){function a(a){this.position=a||0}a.prototype={constructor:a,advance:function(){this.position++},clone:function(){var b=new a;b.position=this.position;return b},retreat:function(){this.position=Math.max(--this.position,0)}};return a});
KISSY.add("html-parser/lexer/index",[],function(){function a(){this.lineCursors=[]}a.prototype={constructor:a,add:function(a){var c;a:{c=this.lineCursors;for(var f=a.position,d=0;d<c.length;d++){var h=c[d].position;if(h===f){c=-1;break a}if(h>f)break}c=d}-1!==c&&this.lineCursors.splice(c,0,a.clone())},remove:function(a){var c=this.lineCursors,f;a:{f=this.lineCursors;for(var a=a.position,d=0;d<f.length;d++){var h=f[d].position;if(h===a){f=d;break a}if(h<a)break}f=-1}-1!==f&&c.splice(f,1)},row:function(a){for(var c=
this.lineCursors,f=0;f<c.length;f++)if(c[f].position>a.position)return f-1;return f},col:function(a){var c=0,f=this.lineCursors[this.row(a)-1];f&&(c=f.position);return a.position-c}};return a});
KISSY.add("html-parser/lexer/page",["./index"],function(a,b){function c(d){this.source=d;this.lineIndex=new f}var f=b("./index");c.prototype={constructor:c,getChar:function(d){var a=this.source,g=d.position;if(g>=a.length)return-1;var c=a.charAt(g);d.advance();"\r"===c&&(c="\n",g=d.position,"\n"===a.charAt(g)&&d.advance());"\n"===c&&this.lineIndex.add(d);return c},ungetChar:function(d){var a=this.source;d.retreat();var c=d.position,b=a.charAt(c);"\n"===b&&0!==c&&(b=a.charAt(c-1),"\r"===b&&d.retreat())},
getText:function(d,a){return this.source.slice(d,a)},row:function(d){return this.lineIndex.row(d)},col:function(d){return this.lineIndex.col(d)}};return c});
KISSY.add("html-parser/nodes/node",[],function(){function a(a){var b=0;a.replace(/\n/g,function(){b++});return b}function b(a,b,d){this.parentNode=null;this.page=a;this.startPosition=b;this.endPosition=d;this.nextSibling=this.previousSibling=this.nodeName=null}b.prototype={constructor:b,getStartLine:function(){if(this.page){if("startLine"in this)return this.startLine;this.startLine=a(this.page.getText(0,this.startPosition))}return-1},getEndLine:function(){if(this.page){if("endLine"in this)return this.endLine;
this.endLine=a(this.page.getText(0,this.endPosition))}return-1},toHtml:function(){return this.page&&this.page.getText?this.page.getText(this.startPosition,this.endPosition):""},toDebugString:function(){var a=[];a.push(this.nodeName+"  [ "+this.startPosition+"|"+this.getStartLine()+" : "+this.endPosition+"|"+this.getEndLine()+" ]\n");a.push(this.toHtml());return a.join("")}};return b});
KISSY.add("html-parser/nodes/text",["./node"],function(a,b){function c(d){"string"===typeof d?(this.nodeValue=d,c.superclass.constructor.apply(this,[null,-1,-1])):(c.superclass.constructor.apply(this,arguments),this.nodeValue=this.toHtml());this.nodeType=3;this.nodeName="#text"}var f=b("./node");a.extend(c,f,{writeHtml:function(d,a){var c;if(!a||!1!==(c=a.onText(this)))c&&this!==c?c.writeHtml(d,a):d.text(this.toHtml())},toHtml:function(){return this.nodeValue?this.nodeValue:c.superclass.toHtml.apply(this,
arguments)}});return c});KISSY.add("html-parser/nodes/cdata",["./text"],function(a,b){function c(){c.superclass.constructor.apply(this,arguments);this.nodeType=4;this.nodeName="#cdata"}var f=b("./text");a.extend(c,f,{writeHtml:function(a,c){var b;if(!c||!1!==(b=c.onCData(this)))b&&this!==b?b.writeHtml(a,c):a.cdata(this.toHtml())}});return c});
KISSY.add("html-parser/utils",[],function(){return{isBooleanAttribute:function(a){return/^(?:checked|disabled|selected|readonly|defer|multiple|nohref|noshape|nowrap|noresize|compact|ismap)$/i.test(a)},collapseWhitespace:function(a){return a.replace(/[\s\xa0]+/g," ")},isLetter:function(a){return"a"<=a&&"z">=a||"A"<=a&&"Z">=a},isValidAttributeNameStartChar:function(a){return!this.isWhitespace(a)&&'"'!==a&&"'"!==a&&">"!==a&&a!==""<""&&"/"!==a&&"="!==a},isWhitespace:function(a){return/^[\s\xa0]$/.test(a)}}});
KISSY.add("html-parser/nodes/attribute",[],function(a){function b(a,b,d,h){this.nodeType=2;this.name=a;this.assignment=b;this.value=d;this.quote=h}a.augment(b,{clone:function(){var c=new b;a.mix(c,this);return c},equals:function(a){return this.name===a.name&&this.value===a.value&&this.nodeType===a.nodeType}});b.prototype.clone=function(){var c=new b;a.mix(c,this);return c};return b});
KISSY.add("html-parser/nodes/tag",["./node","./attribute","../dtd"],function(a,b){function c(j,d,n){j.nodeName=j.tagName=d.toLowerCase();j._updateSelfClosed();a.each(n,function(a,d){j.setAttribute(d,a)})}function f(j,d,n,o){this.childNodes=[];this.lastChild=this.firstChild=null;this.attributes=o||[];this.nodeType=1;if("string"===typeof j)c.apply(null,[this].concat(a.makeArray(arguments)));else{f.superclass.constructor.apply(this,arguments);o=this.attributes;o[0]&&(this.nodeName=o[0].name.toLowerCase(),
this.tagName=this.nodeName.replace(/\//,""),this._updateSelfClosed(),o.splice(0,1));var p=o[o.length-1];if(p=!(!p||!/\/$/.test(p.name)))o.length-=1;this.closed=this.isSelfClosed=this.isSelfClosed||p}this.closedEndPosition=this.closedStartPosition=-1}function d(a){var d=a.childNodes;a.firstChild=d[0];a.lastChild=d[d.length-1];1<=d.length&&(d[0].nextSibling=d[0].nextSibling=null,d[0].parentNode=a);if(1<d.length){for(var n=0;n<d.length-1;n++)d[n].nextSibling=d[n+1],d[n+1].previousSibling=d[n],d[n+1].parentNode=
a;d[d.length-1].nextSibling=null}}function h(a,d){if(a&&a.length)for(var n=0;n<a.length;n++)if(a[n].name===d)return a[n];return null}var g=b("./node"),l=b("./attribute"),m=b("../dtd");a.extend(f,g,{_updateSelfClosed:function(){this.isSelfClosed=!!m.$empty[this.nodeName];this.isSelfClosed||(this.isSelfClosed=/\/$/.test(this.nodeName));this.closed=this.isSelfClosed},clone:function(){var d=new f,b=[];a.each(this.attributes,function(a){b.push(a.clone())});a.mix(d,{childNodes:[],firstChild:null,lastChild:null,
attributes:b,nodeType:this.nodeType,nodeName:this.nodeName,tagName:this.tagName,isSelfClosed:this.isSelfClosed,closed:this.closed,closedStartPosition:this.closedStartPosition,closedEndPosition:this.closedEndPosition});return d},setTagName:function(a){(this.nodeName=this.tagName=a)&&this._updateSelfClosed()},equals:function(a){if(!a||this.nodeName!==a.nodeName||this.nodeType!==a.nodeType||this.attributes.length!==a.attributes.length)return 0;for(var d=0;d<this.attributes.length;d++)if(!this.attributes[d].equals(a.attributes[d]))return 0;
return 1},isEndTag:function(){return/^\//.test(this.nodeName)},appendChild:function(a){this.childNodes.push(a);d(this)},replace:function(j){var b=j.parentNode.childNodes,n=a.indexOf(j,b);b[n]=this;d(j.parentNode)},replaceChild:function(j,b){var n=this.childNodes,o=a.indexOf(b,n);n[o]=j;d(this)},prepend:function(a){this.childNodes.unshift(a);d(this)},insertBefore:function(j){var b=j.parentNode.childNodes,n=a.indexOf(j,b);b.splice(n,0,this);d(j.parentNode)},insertAfter:function(d){var b=d.parentNode.childNodes,
n=a.indexOf(d,b);n===b.length-1?d.parentNode.appendChild(this):this.insertBefore(d.parentNode.childNodes[[n+1]])},empty:function(){this.childNodes=[];d(this)},removeChild:function(b){var c=b.parentNode.childNodes,n=a.indexOf(b,c);c.splice(n,1);d(b.parentNode)},getAttribute:function(a){return(a=h(this.attributes,a))&&a.value},setAttribute:function(a,d){var n=h(this.attributes,a);n?n.value=d:this.attributes.push(new l(a,"=",d,'"'))},removeAttribute:function(d){(d=h(this.attributes,d))&&this.attributes.splice(a.indexOf(d,
this.attributes),1)},filterChildren:function(){var d=this;if(!d.isChildrenFiltered){var b=new (a.require("html-parser/writer/basic"));d._writeChildrenHTML(b);b=(new (a.require("html-parser/parser"))(b.getHtml())).parse().childNodes;d.empty();a.each(b,function(a){d.appendChild(a)});d.isChildrenFiltered=1}},writeHtml:function(a,d){var b=this,o;o=b.tagName;if("!doctype"===o)a.append(this.toHtml()+"\n");else{b.__filter=d;b.isChildrenFiltered=0;if(d){if(!(o=d.onTagName(o)))return;b.tagName=o;o=d.onTag(b);
if(!1===o)return;o&&(b=o);if(1!==b.nodeType){b.writeHtml(a,d);return}if(!b.tagName){b._writeChildrenHTML(a);return}}a.openTag(b);for(var p=b.attributes,e=0;e<p.length;e++){var i=p[e];o=i.name;if(d){if(!(o=d.onAttributeName(o,b)))continue;i.name=o;if(!1===d.onAttribute(i,b))continue}a.attribute(i,b)}a.openTagClose(b);b.isSelfClosed||(b._writeChildrenHTML(a),a.closeTag(b))}},_writeChildrenHTML:function(d){var b=this.isChildrenFiltered?0:this.__filter;a.each(this.childNodes,function(a){a.writeHtml(d,
b)})}});return f});KISSY.add("html-parser/nodes/comment",["./text"],function(a,b){function c(){c.superclass.constructor.apply(this,arguments);this.nodeType=8;this.nodeName="#comment"}var f=b("./text");a.extend(c,f,{writeHtml:function(a,b){var c;if(!b||!1!==(c=b.onComment(this)))c&&this!==c?c.writeHtml(a,b):a.comment(this.toHtml())},toHtml:function(){if(this.nodeValue)return this.nodeValue;var a=f.superclass.toHtml.apply(this,arguments);return a.substring(4,a.length-3)}});return c});
KISSY.add("html-parser/lexer/lexer","./cursor,./page,../nodes/text,../nodes/cdata,../utils,../nodes/attribute,../nodes/tag,../nodes/comment".split(","),function(a,b){function c(a,b){this.page=new d(a);this.cursor=new f;this.nodeFactory=this;this.cfg=b||{}}var f=b("./cursor"),d=b("./page"),h=b("../nodes/text"),g=b("../nodes/cdata"),l=b("../utils"),m=b("../nodes/attribute"),j=b("../nodes/tag"),k=b("../nodes/comment");c.prototype={constructor:c,setPosition:function(a){this.cursor.position=a},getPosition:function(){return this.cursor.position},
nextNode:function(a){var d,b,e=this.cursor,i=this.page;d=e.position;b=i.getChar(e);switch(b){case -1:a=null;break;case "<":b=i.getChar(e);if(b===-1)a=this.makeString(d,e.position);else if(b==="/"||l.isLetter(b)){i.ungetChar(e);a=this.parseTag(d)}else if("!"===b||"?"===b){b=i.getChar(e);if(b===-1)a=this.makeString(d,e.position);else if(">"===b)a=this.makeComment(d,e.position);else{i.ungetChar(e);if("-"===b)a=this.parseComment(d,a);else{i.ungetChar(e);a=this.parseTag(d)}}}else{i.ungetChar(e);a=this.parseString(d,
a)}break;default:i.ungetChar(e);a=this.parseString(d,a)}return a},makeComment:function(a,d){var b;b=d-a;if(0!==b){if(2>b)return this.makeString(a,d);b=this.nodeFactory.createCommentNode(this.page,a,d)}else b=null;return b},makeString:function(a,d){var b=null;d-a>0&&(b=this.nodeFactory.createStringNode(this.page,a,d));return b},makeCData:function(a,d){var b=null;d-a>0&&(b=this.nodeFactory.createCDataNode(this.page,a,d));return b},makeTag:function(a,d,b){var e;e=d-a;if(0!==e){if(2>e)return this.makeString(a,
d);a=this.nodeFactory.createTagNode(this.page,a,d,b)}else a=null;return a},createTagNode:function(a,d,b,e){return new j(a,d,b,e)},createStringNode:function(a,d,b){return new h(a,d,b)},createCDataNode:function(a,d,b){return new g(a,d,b)},createCommentNode:function(a,d,b){return new k(a,d,b)},parseTag:function(d){var b,c=[],e=[],i,t=this.cfg.strict,g=a.noop,j=this.page,f=0,h=this.cursor;t&&(g=function(){if(t&&i===-1&&e.length)throw Error(e[0].name+" syntax error at row "+(j.row(h)+1)+" , col "+(j.col(h)+
1));});for(c[0]=h.position;!b;){c[f+1]=h.position;i=j.getChar(h);switch(f){case 0:if(i===-1||">"===i||"<"===i){if("<"===i){j.ungetChar(h);c[f+1]=h.position}b=true}else if(i==="/"||l.isValidAttributeNameStartChar(i))f=1;break;case 1:if(-1===i||">"===i||"<"===i){if("<"===i){j.ungetChar(h);c[f+1]=h.getPosition}this.standalone(e,c);b=true}else if(l.isWhitespace(i)){c[6]=c[2];f=6}else"="===i&&(f=2);break;case 2:if(-1===i||">"===i){this.standalone(e,c);b=true}else if("'"===i){f=4;c[4]=c[3]}else if('"'===
i){f=5;c[5]=c[3]}else l.isWhitespace(i)||(f=3);break;case 3:if(-1===i||">"===i){this.naked(e,c);b=true}else if(l.isWhitespace(i)){this.naked(e,c);c[0]=c[4];f=0}break;case 4:if(-1===i){this.singleQuote(e,c);b=true}else if("'"===i){this.singleQuote(e,c);c[0]=c[5]+1;f=0}break;case 5:if(-1===i){this.doubleQuote(e,c);b=true}else if('"'===i){this.doubleQuote(e,c);c[0]=c[6]+1;f=0}break;case 6:if(-1===i){this.standalone(e,c);c[0]=c[6];j.ungetChar(h);f=0}else if("="===i){c[2]=c[6];c[3]=c[7];f=2}else if(!l.isWhitespace(i)){this.standalone(e,
c);c[0]=c[6];j.ungetChar(h);f=0}break;default:throw Error("how ** did we get in state "+f);}g()}return this.makeTag(d,h.position,e)},parseComment:function(a,d){var b,e,c=this.page,j=this.cursor,g;b=false;for(g=0;!b;){e=c.getChar(j);if(-1===e)b=true;else switch(g){case 0:if(">"===e)b=true;else if("-"===e)g=1;else return this.parseString(a,d);break;case 1:if("-"===e){e=c.getChar(j);if(-1===e)b=true;else if(">"===e)b=true;else{c.ungetChar(j);g=2}}else return this.parseString(a,d);break;case 2:if("-"===
e)g=3;else if(-1===e)return this.parseString(a,d);break;case 3:g="-"===e?4:2;break;case 4:">"===e?b=true:l.isWhitespace(e)||(g=2);break;default:throw Error("how ** did we get in state "+g);}}return this.makeComment(a,j.position)},parseString:function(a,d){for(var b=0,e,c=this.page,j=this.cursor,g=0;!b;){e=c.getChar(j);if(-1===e)b=1;else if(d&&0===g&&('"'===e||"'"===e))g=e;else if(d&&0!==g&&"\\"===e){e=c.getChar(j);-1!==e&&"\\"!==e&&e!==g&&c.ungetChar(j)}else if(d&&e===g)g=0;else if(d&&0===g&&e===
"/"){e=c.getChar(j);if(-1===e)b=1;else if("/"===e){do e=c.getChar(j);while(-1!==e&&"\n"!==e)}else if("*"===e){do{do e=c.getChar(j);while(-1!==e&&"*"!==e);e=c.getChar(j);e==="*"&&c.ungetChar(j)}while(-1!==e&&"/"!==e)}else c.ungetChar(j)}else if(0===g&&"<"===e){e=c.getChar(j);if(-1===e)b=1;else{if("/"===e||l.isLetter(e)||"!"===e||"?"===e){b=1;c.ungetChar(j)}c.ungetChar(j)}}}return this.makeString(a,j.position)},parseCDATA:function(a,d){var b,e,c,j,g,f,h=this.cursor,k=this.page;b=h.position;e=0;c=false;
j="";for(f=false;!c;){g=k.getChar(h);switch(e){case 0:switch(g){case -1:c=true;break;case "'":a&&!f&&(""===j?j="'":"'"===j&&(j=""));break;case '"':a&&!f&&(""===j?j='"':'"'===j&&(j=""));break;case "\\":if(a&&""!==j){g=k.getChar(h);-1===g?c=true:g!=="\\"&&g!==j&&k.ungetChar(h)}break;case "/":if(a&&""===j){g=k.getChar(h);if(-1===g)c=true;else if("/"===g)f=true;else if("*"===g){do{do g=k.getChar(h);while(-1!==g&&"*"!==g);g=k.getChar(h);g==="*"&&k.ungetChar(h)}while(-1!==g&&"/"!==g)}else k.ungetChar(h)}break;
case "\n":f=false;break;case "<":a?""===j&&(e=1):e=1}break;case 1:switch(g){case -1:c=true;break;case "/":e=!d||k.getText(h.position,h.position+d.length)===d&&!k.getText(h.position+d.length,h.position+d.length+1).match(/\w/)?2:0;break;case "!":g=k.getChar(h);if(-1===g)c=true;else if("-"===g){g=k.getChar(h);-1===g?c=true:e="-"===g?3:0}else e=0;break;default:e=0}break;case 2:f=false;if(-1===g)c=true;else if(l.isLetter(g)){c=true;k.ungetChar(h);k.ungetChar(h);k.ungetChar(h)}else e=0;break;case 3:f=false;
if(-1===g)c=true;else if("-"===g){g=k.getChar(h);if(-1===g)c=true;else if("-"===g){g=k.getChar(h);if(-1===g)c=true;else if(">"===g)e=0;else{k.ungetChar(h);k.ungetChar(h)}}else k.ungetChar(h)}break;default:throw Error("unexpected "+e);}}return this.makeCData(b,h.position)},singleQuote:function(a,d){var b=this.page;a.push(new m(b.getText(d[1],d[2]),"=",b.getText(d[4]+1,d[5]),"'"))},doubleQuote:function(a,d){var b=this.page;a.push(new m(b.getText(d[1],d[2]),"=",b.getText(d[5]+1,d[6]),'"'))},standalone:function(a,
d){a.push(new m(this.page.getText(d[1],d[2])))},naked:function(a,d){var b=this.page;a.push(new m(b.getText(d[1],d[2]),"=",b.getText(d[3],d[4])))}};return c});KISSY.add("html-parser/nodes/fragment",["./tag"],function(a,b){function c(){this.childNodes=[];this.nodeType=9;this.nodeName="#fragment"}var f=b("./tag");a.extend(c,f,{writeHtml:function(a,b){this.__filter=b;this.isChildrenFiltered=0;if(b)b.onFragment(this);this._writeChildrenHTML(a)}});return c});
KISSY.add("html-parser/nodes/document",["./tag"],function(a,b){function c(){this.childNodes=[];this.nodeType=9;this.nodeName="#document"}var f=b("./tag");a.extend(c,f,{writeHtml:function(a,b){this.__filter=b;this._writeChildrenHTML(a)}});return c});KISSY.add("html-parser/scanners/special-scanners",[],function(){return{}});
KISSY.add("html-parser/scanners/tag-scanner",["../dtd","../nodes/tag","./special-scanners"],function(a,b){function c(b,g){function m(){e.childNodes.length&&(e.insertAfter(i),i=e,e=b.clone())}b.closed=1;if(!g.fixByDtd)return 0;var o=1,p=[].concat(b.childNodes);a.each(p,function(a){if(!f(b,a))return o=0,!1});if(o)return 0;for(var e=b.clone(),i=b,t=[],r=0;r<p.length;r++){var q=p[r];if(f(e,q))e.appendChild(q);else if(1===q.nodeType){var u=q.tagName;if(d.$listItem[u]){m();var q=l[q.tagName],s=new h;for(s.nodeName=
s.tagName=q;r<p.length;){if(p[r].tagName===u)s.appendChild(p[r]);else if(3===p[r].nodeType&&a.trim(p[r].toHtml()))break;r++}s.insertAfter(i);i=s;r--}else m(),q.equals(e)?(q.insertAfter(i),i=q):f(q,e)?(e=b.clone(),a.each(q.childNodes,function(a){e.appendChild(a)}),q.empty(),q.insertAfter(i),i=q,q.appendChild(e),t.push(e),e=b.clone()):(q.insertAfter(i),i=q)}}e.childNodes.length&&e.insertAfter(i);b.parentNode.removeChild(b);a.each(t,function(a){c(a,g)});return 1}function f(a,b){return 9===a.nodeType||
8===b.nodeType?1:!!d[a.tagName][b.tagName||b.nodeName]}var d=b("../dtd"),h=b("../nodes/tag"),g=b("./special-scanners"),l={li:"ul",dt:"dl",dd:"dl"},m={dd:{dl:1},dt:{dl:1},li:{ul:1,ol:1},option:{select:1},optgroup:{select:1}};return{scan:function(a,d,b){function h(d,e){for(i=d;i>e;i--){var g=l[i];l[i-1].appendChild(g);c(g,b)}a=l[e];l.length=e}function f(a){var d=0,b;if(b=m[a.tagName]){for(var e=l.length-1,c=l[e];c&&!(c.tagName in b);){if(c.tagName===a.tagName){d=1;break}e--;c=l[e]}d&&h(l.length-1,e-
1)}return d}var e,i,l;l=b.stack=b.stack||[];do{if(e=d.nextNode())if(1===e.nodeType)if(e.isEndTag()&&e.tagName===a.tagName)e=null;else if(e.isEndTag()){if(e.isEndTag()){var r=-1;for(i=l.length-1;0<=i;i--)if(l[i].tagName===e.tagName){r=i;break}-1!==r&&(l[l.length-1].appendChild(a),c(a,b),h(l.length-1,r),e=null)}}else g[e.tagName]?(g[e.tagName].scan(e,d,b),a.appendChild(e)):e.isSelfClosed?a.appendChild(e):(l.push(a),f(e)&&l.push(a),a=e);else a.appendChild(e);null===e&&0<l.length&&(e=l[l.length-1],g[e.tagName]?
e=null:(l.length-=1,e.appendChild(a),c(a,b),a=e))}while(e);c(a,b)}}});KISSY.add("html-parser/scanners/cdata-scanner",[],function(){return{scan:function(a,b,c){var c=b.parseCDATA(c.quoteSmart,a.nodeName),f=b.getPosition(),d=b.nextNode();d&&(1!==d.nodeType||!(d.isEndTag()&&d.tagName===a.tagName))&&b.setPosition(f);a.closed=!0;c&&a.appendChild(c)}}});
KISSY.add("html-parser/scanners/quote-cdata-scanner",["./cdata-scanner","../dtd","./special-scanners"],function(a,b){var c=b("./cdata-scanner"),f=b("../dtd"),d=b("./special-scanners"),h={scan:function(a,d,b){b=b||{};b.quoteSmart=1;c.scan(a,d,b);b.quoteSmart=0}},g;for(g in f.$cdata)d[g]=h;return h});
KISSY.add("html-parser/scanners/textarea-scanner",["./cdata-scanner","./special-scanners"],function(a,b){var c=b("./cdata-scanner"),f=b("./special-scanners");f.textarea={scan:function(a,b,g){g=g||{};c.scan(a,b,g)}};return f.textarea});
KISSY.add("html-parser/scanner",["./scanners/tag-scanner","./scanners/special-scanners","./scanners/quote-cdata-scanner","./scanners/textarea-scanner"],function(a,b){var c=b("./scanners/tag-scanner"),f=b("./scanners/special-scanners");b("./scanners/quote-cdata-scanner");b("./scanners/textarea-scanner");return{getScanner:function(a){return f[a]||c}}});
KISSY.add("html-parser/parser","./dtd,./nodes/tag,./nodes/fragment,./lexer/lexer,./nodes/document,./scanner".split(","),function(a,b){function c(d,b){this.originalHTML=d=a.trim(d);d=/^(<!doctype|<html|<body)/i.test(d)?"<document>"+d+"</document>":"<body>"+d+"</body>";this.lexer=new k(d);this.opts=b||{}}function f(d){var b=h(d,"body",3);if(b){var d=b.parentNode,c=d.childNodes,g=a.indexOf(b,c);if(g!==c.length-1){c=c.slice(g+1,c.length);for(g=0;g<c.length;g++){d.removeChild(c[g]);c[g].tagName==="body"?
a.each(c[g].childNodes,function(a){b.appendChild(a)}):b.appendChild(c[g])}}}return b}function d(a){var d=a.childNodes,b,c,g=l.p,h=0;for(c=0;c<d.length;c++){b=d[c];if(b.nodeType===3||b.nodeType===1&&g[b.nodeName]){h=1;break}}if(h){var h=[],j=new m;j.nodeName=j.tagName="p";for(c=0;c<d.length;c++){b=d[c];if(b.nodeType===3||b.nodeType===1&&g[b.nodeName])j.appendChild(b);else{if(j.childNodes.length){h.push(j);j=j.clone()}h.push(b)}}j.childNodes.length&&h.push(j);a.empty();for(c=0;c<h.length;c++)a.appendChild(h[c])}}
function h(a,b,d){if(d===0)return 0;typeof d==="number"&&d--;var c=a.childNodes;if(c)for(var g=0;g<c.length;g++){if(c[g].tagName===b)return c[g];if(a=h(c[g],b,d))return a}return 0}function g(d){for(var b=[].concat(d.childNodes),c=0;c<b.length;c++)if(b[c].nodeName==="html"){for(var g=b[c],h=0;h<c;h++)b[h].nodeType===3&&!a.trim(b[h].toHtml())&&d.removeChild(b[h]);for(;g.firstChild&&g.firstChild.nodeType===3&&!a.trim(g.firstChild.toHtml());)g.removeChild(g.firstChild);break}}var l=b("./dtd"),m=b("./nodes/tag"),
j=b("./nodes/fragment"),k=b("./lexer/lexer"),n=b("./nodes/document"),o=b("./scanner");c.prototype={constructor:c,elements:function(){var b,c,h=this.lexer,l=this.opts;c=b=h.nextNode();if(b.tagName!=="document"){c=new n;c.appendChild(b)}c.nodeType=9;o.getScanner("div").scan(b,h,l);(b=f(c))&&l.autoParagraph&&d(b);g(c);var l=this.originalHTML,k=new j;c=/^(<!doctype|<html|<body)/i.test(l)?c.childNodes:b.childNodes;a.each(c,function(a){k.appendChild(a)});return k},parse:function(){return this.elements()}};
return c});
KISSY.add("html-parser/writer/basic",["../utils"],function(a,b){function c(){this.output=[]}var f=b("../utils").isBooleanAttribute;c.prototype={constructor:c,append:function(){for(var a=this.output,b=arguments,c,l=0;l<b.length;l++)if(c=b[l],1<c.length)for(var f=0;f<c.length;f++)a.push(c.charAt(f));else a.push(c);return this},openTag:function(a){this.append("<",a.tagName)},openTagClose:function(a){a.isSelfClosed&&this.append(" ","/");this.append(">")},closeTag:function(a){this.append("</",a.tagName,
">")},attribute:function(a){var b=a.value||"",a=a.name;f(a)&&!b&&(b=a);this.append(" ",a,'="',(""+b).replace(/'/g,"&quot;"),'"')},text:function(a){this.append(a)},cdata:function(a){this.append(a)},comment:function(a){this.append("<\!--"+a+"--\>")},getHtml:function(){return this.output.join("")}};return c});
KISSY.add("html-parser/writer/beautify",["./basic","../dtd","../utils"],function(a,b){function c(){var b=this;c.superclass.constructor.apply(b,arguments);b.inPre=0;b.indentChar="\t";b.indentLevel=0;b.allowIndent=0;b.rules={};var h=a.merge(d.$nonBodyContent,d.$block,d.$listItem,d.$tableContent,{select:1,script:1,style:1}),f;for(f in h)b.setRules(f,{allowIndent:1,breakBeforeOpen:1,breakAfterOpen:1,breakBeforeClose:1,breakAfterClose:1});a.each("p,h1,h2,h3,h4,h5,h6".split(","),function(a){b.setRules(a,
{allowIndent:0,breakAfterOpen:0,breakBeforeClose:0})});b.setRules("option",{breakBeforeOpen:1});b.setRules("optiongroup",{breakBeforeOpen:1});b.setRules("br",{breakAfterOpen:1});b.setRules("title",{allowIndent:0,breakBeforeClose:0,breakAfterOpen:0});b.setRules("pre",{breakAfterOpen:1,allowIndent:0})}var f=b("./basic"),d=b("../dtd"),h=b("../utils");a.extend(c,f,{indentation:function(){this.inPre||this.append(Array(this.indentLevel+1).join(this.indentChar));this.allowIndent=0},lineBreak:function(){var a=
this.output;if(!this.inPre&&a.length){for(var b=a.length-1;0<=b&&/[\r\n\t ]/.test(a[b]);b--);a.length=b+1;this.append("\n")}this.allowIndent=1},setRules:function(b,d){this.rules[b]||(this.rules[b]={});a.mix(this.rules[b],d)},openTag:function(a){var b=this.rules[a.tagName]||{};this.allowIndent?this.indentation():b.breakBeforeOpen&&(this.lineBreak(),this.indentation());c.superclass.openTag.apply(this,arguments)},openTagClose:function(a){var b=a.tagName,d=this.rules[b]||{};a.isSelfClosed?this.append(" />"):
(this.append(">"),d.allowIndent&&this.indentLevel++);d.breakAfterOpen&&this.lineBreak();"pre"===b&&(this.inPre=1)},closeTag:function(a){var b=a.tagName,d=this.rules[b]||{};d.allowIndent&&this.indentLevel--;this.allowIndent?this.indentation():d.breakBeforeClose&&(this.lineBreak(),this.indentation());c.superclass.closeTag.apply(this,arguments);"pre"===b&&(this.inPre=0);d.breakAfterClose&&this.lineBreak()},text:function(a){this.allowIndent&&this.indentation();this.inPre||(a=h.collapseWhitespace(a));
this.append(a)},comment:function(a){this.allowIndent&&this.indentation();this.append("<\!--"+a+"--\>")},cdata:function(b){this.allowIndent&&this.indentation();this.append(a.trim(b))}});return c});
KISSY.add("html-parser/writer/minify",["./basic","../utils"],function(a,b){function c(){c.superclass.constructor.apply(this,arguments);this.inPre=0}var f=b("./basic"),d=b("../utils"),h=a.trim,g=d.isBooleanAttribute,l=d.collapseWhitespace,m=RegExp("^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(?:down|up|over|move|out)|key(?:press|down|up)))$");a.extend(c,f,{comment:function(a){/\[if[^\]]+\]/.test(a)&&(a=a.replace(/^(\[[^\]]+\]>)[\s\xa0]*/,"$1").replace(/[\s\xa0]*(<!\[endif\])$/,
"$1"),c.superclass.comment.call(this,a))},openTag:function(a){"pre"===a.tagName&&(this.inPre=1);c.superclass.openTag.apply(this,arguments)},closeTag:function(a){"pre"===a.tagName&&(this.inPre=0);c.superclass.closeTag.apply(this,arguments)},cdata:function(a){a=h(a).replace(/^(?:[\s\xa0]*\/\*[\s\xa0]*<!\[CDATA\[[\s\xa0]*\*\/|[\s\xa0]*\/\/[\s\xa0]*<!\[CDATA\[.*)/,"").replace(/(?:\/\*[\s\xa0]*\]\]>[\s\xa0]*\*\/|\/\/[\s\xa0]*\]\]>)[\s\xa0]*$/,"");c.superclass.cdata.call(this,a)},attribute:function(a,b){var d=
a.name,c,f=a.value||"";c=a.name;if(!(c=!h(a.value||"")?"input"===b&&"value"===c||m.test(c):0)){c=b.nodeName;var e=a.name,i=a.value||"",i=h(i.toLowerCase());c="script"===c&&"language"===e&&"javascript"===i||"form"===c&&"method"===e&&"get"===i||"input"===c&&"type"===e&&"text"===i||"script"===c&&"type"===e&&"text/javascript"===i||"style"===c&&"type"===e&&"text/css"===i||"area"===c&&"shape"===e&&"rect"===i}if(!c)if(g(d))this.append(" ",d);else{c=b.nodeName;e=a.name;i=a.value||"";/^on[a-z]+/.test(e)?i=
h(i).replace(/^javascript:[\s\xa0]*/i,"").replace(/[\s\xa0]*;$/,""):"class"===e?i=l(h(i)):/^(?:a|area|link|base)$/.test(c)&&"href"===e||"img"===c&&/^(?:src|longdesc|usemap)$/.test(e)||"object"===c&&/^(?:classid|codebase|data|usemap)$/.test(e)||"q"===c&&"cite"===e||"blockquote"===c&&"cite"===e||("ins"===c||"del"===c)&&"cite"===e||"form"===c&&"action"===e||"input"===c&&("src"===e||"usemap"===e)||"head"===c&&"profile"===e||"script"===c&&("src"===e||"for"===e)||/^(?:a|area|object|button)$/.test(c)&&"tabindex"===
e||"input"===c&&("maxlength"===e||"tabindex"===e)||"select"===c&&("size"===e||"tabindex"===e)||"textarea"===c&&/^(?:rows|cols|tabindex)$/.test(e)||"colgroup"===c&&"span"===e||"col"===c&&"span"===e||("th"===c||"td"===c)&&("rowspan"===e||"colspan"===e)?i=h(i):"style"===e&&(i=h(i).replace(/[\s\xa0]*;[\s\xa0]*$/,""));c=(""+i).replace(/"/g,"&quot;");if(!f||/[ "'=<>`]/.test(f))c='"'+c+'"';this.append(" ",d,"=",c)}},text:function(a){this.inPre||(a=l(a));this.append(a)}});return c});
KISSY.add("html-parser/writer/filter",[],function(a){function b(){this.tagNames=[];this.attributeNames=[];this.tags=[];this.comment=[];this.text=[];this.cdata=[];this.attributes=[];this.root=[]}function c(b,c){for(var g=0;b&&g<b.length;g++)a.each(b[g].value,function(a){c=c.replace(a[0],a[1])});return c}function f(a,b,c){var f,m;for(m=0;a&&m<a.length;m++){f=a[m].value;if(!1===(f=f.apply(null,b)))return!1;if(c&&f&&f!==c){if("string"===typeof f){if(c.toHtml()===f)break;c.nodeValue=f;f=c}return this.onNode(f)}}return c}
b.prototype={constructor:b,addRules:function(a,b){var b=b||10,c;for(c in a){var f=this[c];if(f){var m;a:{for(m=0;f&&m<f.length;m++)if(f[m].priority>b)break a;m=f.length}f.splice(m,0,{value:a[c],priority:b})}}},onTagName:function(a){return c(this.tagNames,a)},onAttributeName:function(a){return c(this.attributeNames,a)},onText:function(a){return f.call(this,this.text,[a.toHtml(),a],a)},onCData:function(a){return f.call(this,this.cdata,[a.toHtml(),a],a)},onAttribute:function(a,b){var c;a:{c=this.attributes;
for(var f=0;c&&f<c.length;f++){var m=c[f].value,j,k=a.name;if(m[k]&&!1===(j=m[k].call(null,a.value,b))){c=j;break a}"string"===typeof j&&(a.value=j)}c=a}return c},onComment:function(a){return f.call(this,this.comment,[a.toHtml(),a],a)},onNode:function(a){var b=a.nodeType;if(1===b)return this.onTag(a);if(3===b)return this.onText(a);if(8===b)return this.onComment(a)},onFragment:function(a){return f.call(this,this.root,[a],a)},onTag:function(a){for(var b=["^",a.tagName,"$"],c=this.tags,f,m=0;m<b.length;m++)for(var j=
b[m],k=0;k<c.length;k++)if(f=c[k].value,f[j]){if(!1===(f=f[j](a)))return!1;if(f&&f!==a)return this.onNode(f);if(!a.tagName)return a}return a}};return b});
KISSY.add("html-parser","html-parser/dtd,html-parser/lexer/lexer,html-parser/parser,html-parser/writer/basic,html-parser/writer/beautify,html-parser/writer/minify,html-parser/writer/filter,html-parser/nodes/cdata,html-parser/nodes/comment,html-parser/nodes/node,html-parser/nodes/tag,html-parser/nodes/text".split(","),function(a,b){var c=b("html-parser/dtd"),f=b("html-parser/lexer/lexer"),d=b("html-parser/parser"),h=b("html-parser/writer/basic"),g=b("html-parser/writer/beautify"),l=b("html-parser/writer/minify"),
m=b("html-parser/writer/filter"),j=b("html-parser/nodes/cdata"),k=b("html-parser/nodes/comment"),n=b("html-parser/nodes/node"),o=b("html-parser/nodes/tag"),p=b("html-parser/nodes/text");return{CData:j,Comment:k,Node:n,Tag:o,Text:p,Lexer:f,Parser:d,BasicWriter:h,BeautifyWriter:g,MinifyWriter:l,Filter:m,DTD:c,serialize:function(a,b){var c=new h;a.writeHtml(c,b);return c.getHtml()},parse:function(a){return(new d(a)).parse()}}});
